package com.tinklabs.demo.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.List;

/**
 * Created by Jennifer on 2018/4/14.
 */
public class BaseViewPagerAdapter extends FragmentStatePagerAdapter {

    private List<Fragment> fragments;

    private String[] tabs;

    public BaseViewPagerAdapter(FragmentManager fm, String[] tabs, List<Fragment> fragments) {
        super(fm);
        this.tabs = tabs;
        this.fragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (tabs != null && tabs.length > 0) {
            return tabs[position % tabs.length];
        }
        return "";
    }

    public void setPageTitle(String[] tabs) {
        this.tabs = tabs;
    }


}
